<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nyext="urn:noury-extensions">
  <xsl:output method="text" encoding="Windows-1252"/>

  <xsl:param name="solution" />
  <xsl:param name="outdir" />

  <xsl:include href="functions.xslt" />
  
  <xsl:template name="generate-user-file">
    <xsl:text>
@ECHO OFF
::--------------------------------------------------------------------
:: Usage: "build [/clean | /rebuild | /doc | /release] [/wsdk | /vs80 | /nsdk] [/NoPause]"
::
::                 /clean   - Cleans the project
::                 /rebuild - Cleans and builds the project (default)
::                 /doc     - Creates the documentation for the project
::                 /release - Builds a release version of the project
::
::                 /wsdk    - Uses the Windows SDK environment
::                 /vs80    - Uses the Visual Studio 2005 environment
::                 /nsdk    - Uses the .NET Framework SDK environment
::
::                 /NoPause - Does not pause after completion
::--------------------------------------------------------------------



SETLOCAL
SET NO_PAUSE=0
SET ENV=
SET TARGET=Rebuild
GOTO ARGS



:: -------------------------------------------------------------------
:: Builds the project
:: -------------------------------------------------------------------
:BUILD
msbuild </xsl:text>
    <xsl:value-of select="$solution" />
    <xsl:text>.msbuild /nologo /t:%TARGET% /l:FileLogger,Microsoft.Build.Engine;logfile=build.log;verbosity=minimal;encoding=UTF-8 /l:FileLogger,Microsoft.Build.Engine;logfile=build.detailed.log;verbosity=detailed;encoding=UTF-8

IF ERRORLEVEL 1 (
    msbuild misc\Result.msbuild /t:Failure /nologo /noconlog /v:q
) ELSE (
    msbuild misc\Result.msbuild /t:Success /nologo /noconlog /v:q
)
GOTO END



:: -------------------------------------------------------------------
:: Parse command line argument values
:: Note: Currently, last one on the command line wins (ex: /nsdk /wsdk)
:: -------------------------------------------------------------------
:ARGS
IF NOT "x%~4"=="x" GOTO ERROR_USAGE

:ARGS_PARSE
IF /I "%~1"=="/clean"      SET TARGET=Clean&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/rebuild"    SET TARGET=Rebuild&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/doc"        SET TARGET=Document&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/release"    SET TARGET=Release&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/wsdk"       SET ENV=WSDK&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/vs80"       SET ENV=VS80&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/nsdk"       SET ENV=NSDK&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="/NoPause"    SET NO_PAUSE=1&amp; SHIFT &amp; GOTO ARGS_PARSE
IF /I "%~1"=="-h"          GOTO ERROR_USAGE
IF /I "%~1"=="/?"          GOTO ERROR_USAGE
IF    "%~1" EQU ""         GOTO ARGS_DONE
ECHO Unknown command-line switch: %~1
GOTO ERROR_USAGE

:ARGS_DONE
GOTO SETENV



:: -------------------------------------------------------------------
:: Set environment variables
:: -------------------------------------------------------------------
:SETENV
SET PATH="%CD%\misc\Tools\";%PATH%

IF "x%ENV%x"=="xx" GOTO SETENV_DEFAULT
IF "%ENV%"=="WSDK" (
    IF EXIST "%WINDOWS_SDK_HOME%\SetEnv.Cmd" GOTO SETENV_SDK
    GOTO ERROR_NOWSDK
) ELSE IF "%ENV%"=="VS80" (
    IF EXIST "%VS80COMNTOOLS%\vsvars32.bat" GOTO SETENV_VS80
    GOTO ERROR_NOVS80
) ELSE (
    IF EXIST "%FrameworkSDKDir%\sdkvars.bat" GOTO SETENV_NET
    GOTO ERROR_NONSDK
)

:SETENV_DEFAULT
IF EXIST "%WINDOWS_SDK_HOME%\SetEnv.Cmd" GOTO SETENV_SDK
IF EXIST "%VS80COMNTOOLS%\vsvars32.bat" GOTO SETENV_VS80
IF EXIST "%FrameworkSDKDir%\sdkvars.bat" GOTO SETENV_NET
GOTO ERROR_NOSDK

:SETENV_SDK
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 GOTO ERROR_EXT
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 GOTO ERROR_EXT

CALL "%WINDOWS_SDK_HOME%\SetEnv.Cmd" /Release /x86 /xp
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
COLOR
GOTO BUILD

:SETENV_VS80
CALL "%VS80COMNTOOLS%\vsvars32.bat"
::IF ERRORLEVEL 1 GOTO ERROR_NOVS80
GOTO BUILD

:SETENV_NET
CALL "%FrameworkSDKDir%\sdkvars.bat"
::IF ERRORLEVEL 1 GOTO ERROR_NONSDK
GOTO BUILD



:: -------------------------------------------------------------------
:: Errors
:: -------------------------------------------------------------------
:ERROR_NOWSDK
ECHO The Windows SDK could not be found.
ECHO.
ECHO Please make sure that :
ECHO   * Windows SDK is installed
ECHO   * %%WINDOWS_SDK_HOME%% is defined and correct (C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin)
GOTO END

:ERROR_NOVS80
ECHO Visual Studio 2005 could not be found.
ECHO.
ECHO Please make sure that :
ECHO   * Visual Studio 2005 is installed
ECHO   * %%VS80COMNTOOLS%% is defined and correct (C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\)
GOTO END

:ERROR_NONSDK
ECHO The .NET Framework SDK could not be found.
ECHO.
ECHO Please make sure that :
ECHO   * .NET Framework SDK is installed
ECHO   * %%FrameworkSDKDir%% is defined and correct (C:\Program Files\Microsoft.NET\SDK\v2.0\Bin)
GOTO END

:ERROR_NOSDK
ECHO No proper SDK was found.
ECHO.
ECHO Please install at least one of the following :
ECHO   * Windows SDK
ECHO     - Make sure that %%WINDOWS_SDK_HOME%% is defined and correct (C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin)
ECHO   * Visual Studio 2005
ECHO     - Make sure that %%VS80COMNTOOLS%% is defined and correct (C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\)
ECHO   * .NET Framework SDK
ECHO     - Make sure that %%FrameworkSDKDir%% is defined and correct (C:\Program Files\Microsoft.NET\SDK\v2.0\Bin)
GOTO END

:ERROR_EXT
ECHO Could not activate command extensions
GOTO END

:ERROR_USAGE
ECHO Usage: "build [/clean | /rebuild | /doc | /release] [/wsdk | /vs80 | /nsdk] [/NoPause]"
ECHO.
ECHO                 /clean   - Cleans the project
ECHO                 /rebuild - Cleans and builds the project (default)
ECHO                 /doc     - Creates the documentation for the project
ECHO                 /release - Builds a release version of the project
ECHO.
ECHO                 /wsdk    - Uses the Windows SDK environment
ECHO                 /vs80    - Uses the Visual Studio 2005 environment
ECHO                 /nsdk    - Uses the .NET Framework SDK environment
ECHO.
ECHO                 /NoPause - Does not pause after completion
GOTO END



:: -------------------------------------------------------------------
:: End
:: -------------------------------------------------------------------
:END
@IF NOT "%NO_PAUSE%"=="1" PAUSE
ENDLOCAL
</xsl:text>
  </xsl:template>

  <xsl:template match="/">
    <xsl:call-template name="generate-user-file" />
  </xsl:template>
</xsl:stylesheet>
